<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="Cadastros_CustoBrowser" Title="Academia Triathlon ::: Gerenciamento de Custos" Codebehind="CustoBrowser.aspx.cs" %>

<asp:Content ID="mainContent" ContentPlaceHolderID="mainPlace" runat="Server">

    <script type="text/javascript" src="../includes/default.js"></script>

    <br />
    <div class="Title">
        Gerenciamento de Custos
    </div>
    <br />
    <asp:GridView ID="grdMain" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        CellPadding="4" DataSourceID="dsCusto" ForeColor="#333333" GridLines="None" PageSize="15"
        Width="500px" DataKeyNames="CustoID">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="CustoID">
                <ItemTemplate>
                    <asp:Label ID="lblCustoID" runat="server" Text='<%# Bind("CustoID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Nome" SortExpression="Nome">
                <EditItemTemplate>
                    <asp:TextBox ID="txtNome" MaxLength="35" runat="server" Text='<%# Bind("Nome") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblNome" runat="server" Text='<%# Bind("Nome") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Centro de Custo">
                <EditItemTemplate>
                    <asp:DropDownList ID="cbCentroCusto" runat="server" DataSourceID="dsCentroCusto"
                        DataTextField="Nome" DataValueField="CentroCustoID" SelectedValue='<%# Eval("CentroCustoID")!=""?Eval("CentroCustoID"):"" %>'>
                    </asp:DropDownList><asp:SqlDataSource ID="dsCentroCusto" runat="server" ConnectionString="<%$ ConnectionStrings:AcademiaConnectionString %>"
                        SelectCommand="SELECT [CentroCustoID], [Nome] FROM [CentroCusto]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblCentroCusto" runat="server" Text='<%# Bind("CentroCusto") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Valor" SortExpression="Valor">
                <EditItemTemplate>
                    <asp:TextBox ID="txtValor" MaxLength="6" SkinID="Number" runat="server" Text='<%# Bind("Valor") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblValor" runat="server" Text='<%# Bind("Valor") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Dia do Pagamento" SortExpression="DiaPagamento">
                <EditItemTemplate>
                    <asp:TextBox ID="txtDiaPagto" MaxLength="10" SkinID="Date" runat="server" Text='<%# Bind("DiaPagamento") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblDiaPagto" runat="server" Text='<%# Bind("DiaPagamento") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkEdit" runat="Server" CommandName="Edit">Editar</asp:LinkButton>
                    |
                    <asp:LinkButton ID="lnkDelete" runat="Server" CommandName="Delete" CausesValidation="False"
                        OnClientClick="javascript:return confirm('Deseja realmente excluir este registro?');">Excluir</asp:LinkButton>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="lnkUpdate" runat="Server" CommandName="Update">Salvar</asp:LinkButton>
                    |
                    <asp:LinkButton ID="lnkCancel" runat="Server" CommandName="Cancel" CausesValidation="False">Cancelar</asp:LinkButton>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            Nenhum registro cadastrado.
        </EmptyDataTemplate>
        <RowStyle BackColor="#EFF3FB" />
        <EditRowStyle BackColor="#2461BF" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <br />
    <asp:DetailsView ID="dtlMain" runat="server" AutoGenerateRows="False" CellPadding="4"
        DataSourceID="dsCusto" ForeColor="#333333" GridLines="None" Height="50px" Width="500px"
        DefaultMode="Insert">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <EditRowStyle BackColor="#2461BF" />
        <RowStyle BackColor="#EFF3FB" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
        <Fields>
            <asp:BoundField DataField="CustoID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                SortExpression="CustoID" />
            <asp:TemplateField HeaderText="Nome" SortExpression="Nome">
                <InsertItemTemplate>
                    <asp:TextBox ID="txtNome" MaxLength="35" runat="server" Text='<%# Bind("Nome") %>'></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Centro de Custo" SortExpression="CentroCusto">
                <InsertItemTemplate>
                    <asp:DropDownList ID="cbCentroCusto" runat="server" DataSourceID="dsCentroCusto"
                        DataTextField="Nome" DataValueField="CentroCustoID">
                    </asp:DropDownList><asp:SqlDataSource ID="dsCentroCusto" runat="server" ConnectionString="<%$ ConnectionStrings:AcademiaConnectionString %>"
                        SelectCommand="SELECT [CentroCustoID], [Nome] FROM [CentroCusto]"></asp:SqlDataSource>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Valor" SortExpression="Valor">
                <InsertItemTemplate>
                    <asp:TextBox ID="txtValor" MaxLength="6" SkinID="Number" runat="server" Text='<%# Bind("Valor") %>'></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Dia do Pagamento" SortExpression="DiaPagamento">
                <InsertItemTemplate>
                    <asp:TextBox ID="txtDiaPagto" MaxLength="10" SkinID="Date" runat="server" Text='<%# Bind("DiaPagamento") %>'></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <InsertItemTemplate>
                    <asp:LinkButton ID="lnkInsert" runat="Server" CommandName="Insert">Salvar</asp:LinkButton>
                    |
                    <asp:LinkButton ID="lnkCancel" runat="Server" CommandName="Cancel" CausesValidation="False">Cancelar</asp:LinkButton>
                </InsertItemTemplate>           
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="dsCusto" runat="server" ConnectionString="<%$ ConnectionStrings:AcademiaConnectionString %>"
        SelectCommand="SELECT Custo.CustoID, Custo.Nome, Custo.Valor, CentroCusto.CentroCustoID, CentroCusto.Nome AS CentroCusto, CONVERT (char, Custo.DiaPagamento, 103) AS DiaPagamento FROM Custo LEFT OUTER JOIN CentroCusto ON Custo.CentroCustoID = CentroCusto.CentroCustoID ORDER BY Custo.DiaPagamento"
        DeleteCommand="DELETE FROM Custo WHERE CustoID = @CustoID" InsertCommand="set language portuguese Insert INTO Custo(Nome, CentroCustoID, Valor, DiaPagamento) VALUES (@Nome, @CentroCustoID, @Valor, convert(datetime, @DiaPagamento, 103))"
        UpdateCommand="Update Custo SET CentroCustoID = @CentroCustoID, Valor = @Valor, Nome = @Nome, DiaPagamento = convert(datetime, @DiaPagamento, 103) WHERE (CustoID = @CustoID)" OnInserting="dsCusto_Inserting" OnUpdating="dsCusto_Updating">
        <DeleteParameters>
            <asp:Parameter Name="CustoID" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="CentroCustoID" />
            <asp:Parameter Name="Valor" Type="Decimal"/>
            <asp:Parameter Name="Nome" />
            <asp:Parameter Name="DiaPagamento" />
            <asp:Parameter Name="CustoID" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Nome" />
            <asp:Parameter Name="CentroCustoID" />
            <asp:Parameter Name="Valor" Type="Decimal" />
            <asp:Parameter Name="DiaPagamento" />
        </InsertParameters>
    </asp:SqlDataSource>
</asp:Content>
